package pi.client.gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.SwingUtilities;

@SuppressWarnings("serial")
public class MyPanelEndGame extends MyPanelBase{
	private JButton returnToPerfilPanelButton;
	private ActionListener returnToPerfilPanelEvent;
	
	public MyPanelEndGame(final MyMainPanel mainPanel, String backgroundFilename, int width, int height){
		super(mainPanel, backgroundFilename, width, height);
		setLayout(null);
		
		returnToPerfilPanelButton = new JButton("Continue");
		returnToPerfilPanelButton.setBounds((width/2)-70, (height/2), 140, 30);
		
		
		returnToPerfilPanelEvent = new ActionListener(){			
			@Override public void actionPerformed(ActionEvent event){
				mainPanel.SetCurrentPanel(mainPanel.preGamePanel);
			}
		};
		returnToPerfilPanelButton.addActionListener(returnToPerfilPanelEvent);			

		add(returnToPerfilPanelButton);
	}
	
	@Override protected void Draw(Graphics g){
		super.Draw(g);
		
		Font oldF = g.getFont();
		g.setFont(new Font(Font.SANS_SERIF, Font.CENTER_BASELINE, 20));
		DrawTitle(g, "Game Ended", width/2, 100);

		g.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 26));
		if(mainPanel.playerMe.isWinner == true){
			String message = "You Win!";
			int messagePixelSize = (SwingUtilities.computeStringWidth(g.getFontMetrics(), message)/2);
			
			g.setColor(Color.green);			
			g.drawString(message, width/2 - messagePixelSize, height/2 - 100);
		}else{
			String message = "You Lose!";
			int messagePixelSize = (SwingUtilities.computeStringWidth(g.getFontMetrics(), message)/2);
			
			g.setColor(Color.red);
			g.drawString(message, width/2 - messagePixelSize, height/2 - 100);
		}
		g.setFont(oldF);

	}
}